﻿//AdUtils
var UserPop=
{
addUserPop:function(obj,type)
{
    if(!type) type='info';
    if(!this.UIClass[type])
    {
        alert('not fond cls');
        return;
    }
    this.removeUserPop(type);
    this.removeUserPopData(type);
    if(!obj) return;
    var container=this.UIClass[type].popData;
    for(var i=0;i<obj.length;i++)
    {
        this.pushUserPopData(obj[i],container);
    }
    this.loadUserPop();
}
,clearUserPop:function()
{
    var cls=this.UIClass;
    for(var item in cls)
    {
        this.removeUserPop(item);
        this.removeUserPopData(item);
    }
}
,pushUserPopData:function(obj,container)
{
    var targetZ=this.infoLoadLevel;
    var wh=this.zoomvalue(1,256,targetZ);
    var h=Math.floor(obj.x/wh);
    var v=Math.floor(obj.y/wh);
    var id=targetZ+','+h+','+v;
    if(!container[id]) container[id]=[];
    container[id].push(obj);
}
,removeUserPopData:function(type)
{
    var container=this.UIClass[type].popData;
    for(var item in container)
    {
        var arr=container[item];
        for(var i=0;i<arr.length;i++)
        {
            delete arr[i];
        }
        delete container[item];
    }
    container=
    {
    };
}
,loadUserPop:function()
{
    var targetZ=this.infoLoadLevel;
    var wh=this.zoomvalue(this.Zoom,256,targetZ);
    if(!this.isLoadInfo||this.Zoom>this.infoViewLevel||this.mapType!=3) return;
    for(var y=Math.floor(this.startY/wh);y<=Math.floor(this.endY/wh);y++)
    {
        for(var x=Math.floor(this.startX/wh);x<=Math.floor(this.endX/wh);x++)
        {
            this.parseUserPopData(x,y,targetZ);
        }
    }
}
,removeUserPop:function(type)
{
    var targetZ=this.infoLoadLevel;
    var wh=this.zoomvalue(this.Zoom,256,targetZ);
    if(!this.isLoadInfo||this.Zoom>this.infoViewLevel||this.mapType!=3) return;
    var cls=this.UIClass[type];
    var container=cls.popData;
    for(var y=Math.floor(this.startY/wh);y<=Math.floor(this.endY/wh);y++)
    {
        for(var x=Math.floor(this.startX/wh);x<=Math.floor(this.endX/wh);x++)
        {
            var arr=container[targetZ+','+x+','+y];
            if(!arr) continue;
            for(var i=0;i<arr.length;i++)
            {
                this.removePop(cls.getIdStr(arr[i]));
            }
        }
    }
}
,parseUserPopData:function(h,v,z)
{
    var id=z+','+h+','+v;
    var cls=this.UIClass;
    for(var item in cls)
    {
        var ui=cls[item];
        ui.createUserPopById(id);
    }
}
,createUserPop:function(e,param,type)
{
    if(!type) type='info';
    return this.UIClass[type].createUserPop(e,param);
}
,addUserPopClass:function(type,cls)
{
    this.UIClass[type]=new cls(this);
    this.objs[type]=[];
}
,createEmptyUP:function(type)
{
    var elm=document.createElement('div');
    elm._node=type;
    return elm;
}
,popObj:function(type)
{
    return this.objs[type].pop();
}
,getElementById:function(id)
{
    return $(id);
}
};